export function formatSeconds(value) {
  // console.log(value)
  if (value == null || value === 0) {
    return '00:00'
  }
  value = value - 0
  if (value < 0) {
    value = -value
  }
  var secondTime = parseInt(value)// 秒
  var minuteTime = 0// 分
  var hourTime = 0// 小时
  if (secondTime > 60) { // 如果秒数大于60，将秒数转换成整数
    // 获取分钟，除以60取整数，得到整数分钟
    minuteTime = parseInt(secondTime / 60)
    // 获取秒数，秒数取佘，得到整数秒数
    secondTime = parseInt(secondTime % 60)
    // 如果分钟大于60，将分钟转换成小时
    if (minuteTime > 60) {
      // 获取小时，获取分钟除以60，得到整数小时
      hourTime = parseInt(minuteTime / 60)
      // 获取小时后取佘的分，获取分钟除以60取佘的分
      minuteTime = parseInt(minuteTime % 60)
    }
  }
  var result = '' // 秒

  if (minuteTime > 0 && hourTime > 0) {
    if (hourTime < 10) {
      hourTime = '0' + hourTime
    }
    if (minuteTime < 10) {
      minuteTime = '0' + minuteTime
    }
    result = hourTime + ':' + minuteTime // 分
  }
  if (hourTime <= 0 && minuteTime > 0) {
    if (minuteTime < 10) {
      minuteTime = '0' + minuteTime
    }
    result = '00:' + minuteTime // 小时
  }
  if (hourTime <= 0 && minuteTime <= 0) {
    result = '00:00' // 小时
  }
  // return str + result;
  return result
}

// 格式化时间
export function parseToString(date, format) {
  // console.log('parseToString:' + date)
  if (date === undefined || date === null || date === '') {
    return ''
  }
  if (format === undefined || format === null || format === '') {
    format = 'yyyy-MM-dd HH:mm:ss'
  }
  if ((typeof date === 'string') && date.constructor === String) {
    // console.log('parseToString String:' + date)
    date = new Date(date)
  }

  if ((typeof date === 'number') && (date.constructor === Number)) {
    date = new Date(date)
  }

  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  var hours = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()
  var mills = date.getMilliseconds()

  month = month < 10 ? '0' + month : month
  day = day < 10 ? '0' + day : day
  hours = hours < 10 ? '0' + hours : hours
  minute = minute < 10 ? '0' + minute : minute
  second = second < 10 ? '0' + second : second
  mills = mills < 10 ? '00' + mills : mills < 100 ? '0' + mills : mills

  if (format === 'yyyy-MM-dd HH:mm:ss') {
    return year + '-' + month + '-' + day + ' ' + hours + ':' + minute + ':' + second
  } else if (format === 'yyyy-MM-dd') {
    return year + '-' + month + '-' + day
  } else if (format === 'MM/dd/yyyy') {
    return month + '/' + day + '/' + year
  } else if (format === 'MM/dd/yyyy HH:mm:ss') {
    return month + '/' + day + '/' + year + ' ' + hours + ':' + minute + ':' + second
  } else if (format === 'MMddyyyy') {
    return month + '' + day + '' + year
  } else if (format === 'MMddHHmmssSSS') {
    return month + day + hours + minute + second + mills
  } else {
    return date
  }
}
